<?php
/**
 * @version      $Id$
 * @package      Neon
 * @copyright    Copyright (C) FreebandTech. All rights reserved.
 * @license      GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */
// No direct access
error_reporting(0);

$app = JFactory::getApplication('site');
$componentParams = $app->getParams('com_brinkmanvm');
$pathImages = $componentParams->get('pathimages', '/var/www/sandbox.freebandtech.com/brinkman/images_catalog/');
$imageDefault = $componentParams->get('imageDefault', '/var/www/sandbox.freebandtech.com/brinkman/images_catalog/noimage_bkm.png');

$p_sku = JRequest::getString('p_sku', '', GET);
$p_sku = strtolower($p_sku);
$filename = $pathImages.'product/'.$p_sku.'.jpg';


if (file_exists($filename)):

    $fileRender = $filename;

else: //show default picture

    $fileRender = $imageDefault;

endif;

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo,$fileRender);
header('Content-Type: '.$mime);
header('Content-Length: ' . filesize($fileRender));
echo file_get_contents($fileRender);
JFactory::getApplication()->close();

/*
index.php?option=com_brinkmanvm&view=image&format=raw&p_sku=p14030015
index.php?option=com_brinkmanvm&view=image&format=raw&p_sku=P14030015
*/
?>
